package com.mybatiscore.jiaocheng.d04mybatis动态Sql;

import com.mybatiscore.Mapper.StudentMapper;
import com.mybatiscore.POJO.Student;
import com.mybatiscore.Util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class d01_if {
    /*
        if标签:<if test=" "></if>
        test:值为boolean,为true才执行标签中的语句
     */
    @Test
    public void testIF(){
        SqlSession sqlSession = SqlSessionUtil.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        //全不为null
        List<Student> students = mapper.selectByIf("李", '男');
        students.forEach(data-> System.out.println(data));
        //有为null
        List<Student> students1 = mapper.selectByIf("李", null);
        students1.forEach(student -> System.out.println(student));
        //全为null
        List<Student> students2 = mapper.selectByIf(null, null);
        students2.forEach(student -> System.out.println(student));
    }

}
